<?php
/**
 * Interface 商品接口
 * 定义接口
 */
interface IGoods {
    public function Price ();
}

//苹果笔记本
class MacBook implements IGoods{
    public function Price () {
        echo 'price=8888rmb'.PHP_EOL;
    }
}

//华为笔记本
class MateBook implements IGoods {
    public function Price () {
        echo 'price=6999rmb'.PHP_EOL;
    }
}

class Service {
    public static function getGoods($name='') {
        if ($name === 'xps') {return new MateBook();}
        if ($name === 'macbook') {return new MacBook();}
        throw new Exception("not object ".PHP_EOL);
    }
}

try{
    $obj =  Service::getGoods();
} catch  (Exception $e){
    echo $e->getMessage(); // not object
}

try{
    $obj =  Service::getGoods('xps');
    $obj->Price(); // price=6999rmb
} catch  (Exception $e){
    echo $e->getMessage();
}